﻿using Polly;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace Odyssey.Http
{
    interface IPollyHttpRequester
    {
        Task<T> RetryAsync<T>(Func<IHttpRequester, Task<T>> requestExecuter, int retryCount, Func<HttpRequestException, int, Task> onRetry);

        Policy BuildRetryPolicy(int retryCount, Func<HttpRequestException, int, Task> onRetry);

        Task<T> WaitAndRetryAsync<T>(Func<IHttpRequester, Task<T>> requestExecuter, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, Task> onWaitAndRetry);

        Policy BuildWaitAndRetryPolicy(IEnumerable<TimeSpan> sleepDurations, Func<HttpRequestException, TimeSpan, Task> onWaitAndRetry);

        Task<T> TimeoutAsync<T>(Func<IHttpRequester, Task<T>> requestExecuter, Func<Task> onTimeout, int timeoutSeconds);

        Policy BuildTimeoutPolicy(Func<Task> onTimeout, int timeoutSeconds);

        Task<T> WrapAsync<T>(Func<IHttpRequester, Task<T>> requestExecuter, params Policy[] policies);
    }
}
